@extends('layouts.wechat.application')

@section('content')
    <div class="page-product-view" data-log="商品详情">

        <div class="header">
            <div class="left">
                <a onclick="history.go(-1)" class="home">
                    <img src="http://s1.mi.com/m/images/m/icon_back_n.png" class="ib">
                </a>
            </div>
            <div class="tit"></div>
            <div class="right">
                <a href="/search">
                    <div class="icon icon-search"></div>
                </a>
            </div>
        </div>
        <div class="product-view">
            <div class="flexslider ">
                <ul class="slides">

                    @foreach($product->product_galleries as $product_gallery)
                        <li>
                            <a href=""><img src="{{$product_gallery->img}}"></a>
                        </li>
                    @endforeach

                </ul>
            </div>
        </div>
        <div class="b2">
            <div class="b21">
                <div class="b211">
                    <div class="name"><p>{{$product->name}} </p></div>
                    <div class="price"><strong>{{$product->price}}元</strong></div>
                </div>
                <div class="b212">
                    <div class="icon-fenxiang"></div>
                </div>
            </div>
            <div class="b22">
                <p>{{$product->description}}</p>
            </div>
        </div>
        <div class="mt20" style="display: none;"></div>

        <!--<ul class="b3">-->
        <!--<li><span class="on">白色</span></li>-->
        <!--</ul>-->

        <ul class="b3" style="display: none;">
            <li><span>通用</span></li>
        </ul>

        <div class="ui-b7">
            <h3>为您推荐</h3>
            <div class="ui-carousel-container">
                <div class="ui-carousel-viewport">

                    @foreach($recommends as $recommend)
                        <a href="{{route('product.show',['id'=>$recommend->id])}}">
                            <img src="{{$recommend->thumb}}" style="width: 150px;height: 120px;">
                        </a>
                    @endforeach

                </div>
            </div>
        </div>
        <div class="b5">
            <div class="b51"></div>
            <div class="b52">
                <div class="blc">

                    {!! $product->markdown_html_code !!}

                </div>
            </div>
        </div>
        <div class="b7">
            <div class="b70">
                <a href="/">
                    <div class="icon-home"></div>
                </a>
            </div>
            <div class="b72" data-id="{{$product->id}}">
                @if($product->stock == 0)
                    <a href="javascript:;" class="off">暂时缺货</a>
                @else
                    <a href="javascript:;" id="add_to_cart">立即购买</a>
                @endif
            </div>

            <div class="b73">
                <a href="/cart">
                    <div class="icon-gouwuche"></div>
                </a>
            </div>
        </div>
        <a href="javascript:;" id="top" style="visibility: visible;">
            <img src="/wechat/assets/images/top.png">
        </a>
    </div>
    <div class="share-component"></div>
    </div>

@endsection

@section('js')
    <script>
        $(function () {
            //添加商品到购物车
            $("#add_to_cart").click(function () {
                var product_id = $(this).parent('.b72').data('id');
                $.ajax({
                    type: 'POST',
                    url: '/cart',
                    data: {product_id: product_id},
                    success: function (data) {
                        location.href = '/cart';
                    }
                })
            });

            //置顶
            $("#top").click(function () {
                $("html,body").animate({scrollTop: 0}, 300);
            });
        })
    </script>
@endsection